import { configureStore, combineReducers } from "@reduxjs/toolkit";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";

//持久化配置
const persistConfig = {
  key: "root",
  storage,
};

//引入模块切片
import CitySlice from "./CitySliceReducer";
import UserSlice from "./UserSliceReducer";
import AddPersonSlice from "./AddPersonReducer";

//combineReducers合并多个reducer
const rootReducer = combineReducers({
  CitySlice,
  UserSlice,
  AddPersonSlice,
});

//持久化reducer
const persistedReducer = persistReducer(persistConfig, rootReducer);

const store = configureStore({
  reducer: persistedReducer,
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: {
        ignoredActions: ["persist/PERSIST"],
      },
    }),
});

export let persistor = persistStore(store);

export default store;
